// BinarySearch.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"

typedef int KeyType;
typedef struct 
{
	KeyType key;
}DataType;
#define MaxSize 100


#include "SeqList.h"
//#include "SearchPublic.h"



int _BinarySeach(SeqList S, DataType x)
{
	int low =0, high = S.size-1;
	int mid;

	while(low <= high)
	{
		mid = (low + high)/2;
		if(x.key == S.list[mid].key) return mid;
		else if(x.key < S.list[mid].key) high = mid -1;
		else if(x.key > S.list[mid].key) low = mid + 1;
	}
	return -1;
}

int _tmain(int argc, _TCHAR* argv[])
{
	//SeqList s = {{{21},{1},{2},{3},{5},{10},{0},{889},{32},{11}},10};
	SeqList s = {{21,1,2,3,5,10,0,333,889,112,32,111},12};
	DataType x = {889};
	int i;
	if((i = _BinarySeach(s,x)) == -1)
		printf("Cannot find %d !",x.key);
	else printf("The location is: %d",i);

	getchar();
	return 0;
}

